//点击选择卡槽类型
function chooseCardTrough() {
	var hostName = $("#hostName").val();
	var cardId = $("#cardId").val();
	var isOpenCallsDisplay = $("#hidden_feeIllustrate").val();
	var productId = $("#hidden_productId").val();
	var cardTrough = $("#hidden_cardTrough").val();
	if(isOpenCallsDisplay == ""){
		isOpenCallsDisplay = true;
	}
	if(hostName != "" && cardId != "") {
		window.location.href = "chooseCardTrough.jhtml?productId="+productId+"&cardTrough="+ cardTrough +"&isOpenCallsDisplay="+ isOpenCallsDisplay +"&hostName="+ hostName +"&cardId="+ cardId +"";
	}else{
		window.location.href = "chooseCardTrough.jhtml?productId="+productId+"&cardTrough="+ cardTrough +"&isOpenCallsDisplay="+ isOpenCallsDisplay +"";
	}
	
}
//校验是否选择了卡槽类型
function checkChooseCardTrough() {
	var selectedCardTrough = $("#selectCardTrough").html();
	var productId = $("#hidden_productId").val();
	if(selectedCardTrough == "") {
		$.message("error", "请先选择卡槽类型");
		return;
	}else {
		var hostName = $("#hostName").val();
		var cardId = $("#cardId").val();
		var cardTrough = $("#hidden_cardTrough").val();
		var isOpenCallsDisplay = $("#hidden_feeIllustrate").val();
		if(isOpenCallsDisplay == ""){
			isOpenCallsDisplay = true;
		}
		if(selectedCardTrough == "NANO卡"){
			window.location.href = "chooseNum.jhtml?productId="+productId+"&selectedCardTrough=nanoCard&hostName="+ hostName +"&cardId="+ cardId +"&cardTrough="+ cardTrough +"&isOpenCallsDisplay="+ isOpenCallsDisplay +"";
		}
		if(selectedCardTrough == "普卡+微卡双切"){
			window.location.href = "chooseNum.jhtml?productId="+productId+"&selectedCardTrough=commonCard&hostName="+ hostName +"&cardId="+ cardId +"&cardTrough="+ cardTrough +"&isOpenCallsDisplay="+ isOpenCallsDisplay +"";
		}
	}
}
//校验是否选择了电话号码
function checkoutPhoneNum() {
	var selectedPhoneNum = $("#selectPhoneNum").html();
	if(selectedPhoneNum == "请选择号码" || selectedPhoneNum == "") {
		$.message("error", "请先选择号码");
		return;
	}else{
		window.location.href = "choosePackage.jhtml?selectedPhoneNum=" + selectedPhoneNum + "";
	}
}
//资费说明事件
function feeIllustrate() {
	var selectedCardTrough = $("#selectCardTrough").html();
	var selectedPhoneNum = $("#selectPhoneNum").html();
	var defaultCallsDisplay = $("#hidden_feeIllustrate").val();
	var productId = $("#hidden_productId").val();
	var currentLocation = "chooseNumDec";
	var hostName = $("#hostName").val();
	var cardId = $("#cardId").val();
	var cardTrough = $("#hidden_cardTrough").val();
	if(defaultCallsDisplay == "") {
		defaultCallsDisplay = true;
	}
	if(selectedCardTrough == "") {
		window.location.href = "feeIllustrate.jhtml?productId="+productId+"&hostName="+ hostName +"&cardId="+ cardId +"&cardTrough="+ cardTrough +"&defaultCallsDisplay="+ defaultCallsDisplay +"&currentLocation="+ currentLocation +"";
	}
	if(selectedCardTrough == "NANO卡"){
		window.location.href = "feeIllustrate.jhtml?productId="+productId+"&hostName="+ hostName +"&cardId="+ cardId +"&cardTrough="+ cardTrough +"&defaultCallsDisplay="+ defaultCallsDisplay +"&selectedCardTrough=nanoCard&selectedPhoneNum=" + selectedPhoneNum + "&currentLocation="+ currentLocation +"";
	}
	if(selectedCardTrough == "普卡+微卡双切"){
		window.location.href = "feeIllustrate.jhtml?productId="+productId+"&hostName="+ hostName +"&cardId="+ cardId +"&cardTrough="+ cardTrough +"&defaultCallsDisplay="+ defaultCallsDisplay +"&selectedCardTrough=commonCard&selectedPhoneNum=" + selectedPhoneNum + "&currentLocation="+ currentLocation +"";
	}
}
//点击添加用户信息改变样式
function clickAddUserMassage() {
	if($("#addUserMessageSpan").html() == "添加用户信息") {
		$("#addUserMessageSpan").html("用户信息");
		//改变向下箭头
	}else{
		$("#addUserMessageSpan").html("添加用户信息");
		//改变向右箭头
	}
}
//全局变量判机主姓名是否为空、身份证号是否为空及格式是否正确
var hostNameFlag = false;
var cardIdFlag = false;

//校验机主姓名和身份证号
function checkoutHostName(){
	if($("#hostName").val() == ""){
		$.message("error", "请填写机主姓名！");
		hostNameFlag = false;
		return;
	}else{
		hostNameFlag = true;
	}
}
function checkoutCartId(){
	
	//18位身份证号正则表达式(含尾号为X的)
	var regx = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
	var cardId = $("#cardId").val();
	if(cardId == ""){
		$.message("error", "请填写身份证号!");
		cardIdFlag = false;
		$("#hidden_cardIdFlag").attr("value", cardIdFlag);
		return;
	}else if(!regx.test(cardId)) {
		$.message("error", "请输入正确身份证号!");
		cardIdFlag = false;
		$("#hidden_cardIdFlag").attr("value", cardIdFlag);
		return;
	}else{
		cardIdFlag = true;
		$("#hidden_cardIdFlag").attr("value", cardIdFlag);
	}
}

//点击一键购买事件
function submitPhoneNumAndPhonePackage() {
	//此方法不用了，写在当前页面中
	//校验是否选择了号码
	var selectedPhoneNum = $("#selectPhoneNum").html();
	if(selectedPhoneNum == "请选择号码" || selectedPhoneNum == "") {
		alert("请先选择号码");
		return;
	}
	//校验是否选择了套餐
	var phonePackage = $("#phonePackage").html();
	if(phonePackage == "请选择套餐") {
		alert("请选择套餐");
		return;
	}
	if(!hostNameFlag) {
		alert("机主姓名不能为空！");
		return;
	}
	if(!cardIdFlag){
		alert("请输入正确身份证号!");
		return;
	}
	//入网协议是否被选中
	if($("#agreementCheckboxId").attr("checked") != "checked") {
		alert("请选择入网协议并认真阅读!");
		return;
	}
	$("#hidden_hostName").attr("value", $("#hostName").val());
	$("#hidden_cardId").attr("value", $("#cardId").val());
	
	$("#submitForm").attr("action","${base}/weixin/member/order/submitInfo.jhtml");
	$("#submitForm").submit();
	
}

//入网协议
function clickAgreement() {
	var selectedCardTrough = $("#selectCardTrough").html();
	var selectedPhoneNum = $("#selectPhoneNum").html();
	var currentLocation = $("#hidden_currentLocation").val();
	var defaultCallsDisplay = $("#hidden_feeIllustrate").val();
	if(defaultCallsDisplay == "") {
		defaultCallsDisplay = true;
	}
	var hostName = $("#hostName").val();
	var cardId = $("#cardId").val();
	if(cardId != ""){
		var regx = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
		if(!regx.test(cardId)) {
			$.message("error", "请输入正确身份证号");
			cardIdFlag = false;
			$("#hidden_cardIdFlag").attr("value", cardIdFlag);
			return;
		}else{
			cardIdFlag = true;
			$("#hidden_cardIdFlag").attr("value", cardIdFlag);
		}
	}
	//alert("selectedCardTrough:"+selectedCardTrough+"selectedPhoneNum:"+selectedPhoneNum+"defaultCallsDisplay:"+defaultCallsDisplay+"hostName:"+hostName+"cardId:"+cardId);
	if(selectedCardTrough == "") {
		window.location.href = "agreement.jhtml?defaultCallsDisplay="+ defaultCallsDisplay +"&selectedPhoneNum=" + selectedPhoneNum + "&currentLocation="+ currentLocation +"&hostName="+ hostName +"&cardId="+ cardId +"";
	}
	if(selectedCardTrough == "NANO卡"){
		window.location.href = "agreement.jhtml?defaultCallsDisplay="+ defaultCallsDisplay +"&selectedCardTrough=nanoCard&selectedPhoneNum=" + selectedPhoneNum + "&currentLocation="+ currentLocation +"&hostName="+ hostName +"&cardId="+ cardId +"";
	}
	if(selectedCardTrough == "普卡+微卡双切"){
		window.location.href = "agreement.jhtml?defaultCallsDisplay="+ defaultCallsDisplay +"&selectedCardTrough=commonCard&selectedPhoneNum=" + selectedPhoneNum + "&currentLocation="+ currentLocation +"&hostName="+ hostName +"&cardId="+ cardId +"";
	}
}